/**
 * Created by Administrator on 2016/9/18.
 */

myApp
    .controller('sumCostCtrl', function ($cookieStore,$scope, $http,CONFIG ,$window) {

        /*根据user cookie 初始化加载菜单*/
        $scope.userName = $cookieStore.get("userName");

        $scope.getDayCostLog = function(date){
            /*加载消费记录*/
            var url = CONFIG.mainConfig.url+"/customerCost/queryDayCost";
            $http({
                method: 'post',
                url: url,
                params: {
                    date: date,
                    token: $cookieStore.get("token")
                }
            })
                .success(function (result) {

                    if (result.resultCode == 001) {
                        $scope.costList = result.costList;
                    }
                    else {
                        alert(result.resultMsg);
                    }

                })
                .error(function () {
                    alert("error");
                });
        };

        function getNowFormatDate(addDayNum) {
            var date = new Date();
            date.setDate(date.getDate()+addDayNum);
            var seperator = "-";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentDate = year + seperator + month + seperator + strDate;
            return currentDate;
        }

        $scope.qiantian = getNowFormatDate(-2);
        $scope.zuotian = getNowFormatDate(-1);
        $scope.jintian = getNowFormatDate(0);

    });